<template>
	<view class="content padding-top-01">

		<view class="" style="padding: 24rpx;">
			<view class="display-flex flex-end">
				<button style="width: 30px;" open-type="share">
					<uv-icon name="share-square" size="30" color="#999999"></uv-icon>
				</button>
			</view>
			<view class="font-size-28 font-weight-500">
				{{info.title}}
			</view>
			<view class="display-flex align-items margin-top-20">
				<view class="font-size-24 color-999">
					{{(info.like_num / 10000).toFixed(2)}}万人学习
				</view>
				<view class="font-size-24 color-999 margin-left-40 display-flex align-items">
					<uv-icon name="clock" color="#999999"></uv-icon> <text class="margin-left-10">
						{{info.create_time}}</text>
				</view>
			</view>
			<view class="margin-top-20">
				<uv-parse :content="info.content"></uv-parse>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive
	} from 'vue';
	import {
		onLoad,
		onShow,
		onReady,
		onReachBottom,
		onShareAppMessage,
		onShareTimeline
	} from '@dcloudio/uni-app';
	import {
		imgaeUrl,
		nativeUI,
		navigateTo,
		navigateBack,
		timestampToDate
	} from '@/utils/index.js';
	import * as api from '@/request/app.js'; // 引入api 方法
	import local from '@/utils/localStorage.js'; //引入本地存储方法
	const info = ref({})
	const id = ref('')
	onLoad(function(option) {
		id.value = option.id
		if (local.get('token')) {
			getSchoolInfo()
		} else {
			getLogincode()
		}
	});
	onShow(function() {});
	async function getLogincode() {
		const ret = await uni.login()
		console.log(ret.errMsg);
		if (ret.errMsg == 'login:ok') {
			login(ret.code)
		}
	}
	async function login(code) {
		const ret = await api.login({
			code,
			puserid: local.get('puserId') || 0
		})
		if (ret.code == 0) {
			local.set('token', ret.data.token)
			getuserinfo()
		}
	}
	async function getuserinfo() {
		const {
			code,
			data
		} = await api.getuserinfo()
		if (code == 0) {
			local.set('userinfo', data)
			getSchoolInfo()
		}
	}
	async function getSchoolInfo() {
		let object = {
			id: id.value
		}
		const {
			code,
			data
		} = await api.getSchoolInfo(object)
		if (code == 0) {
			info.value = data
		}
	}
	onReady(function() {});
	onReachBottom(function() {

	});
	const pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面
	// 获取到当前页面的路径和参数
	const page = pages[pages.length - 1].route; //完整路由地址
	onShareAppMessage(function(res) {
		return {
			title: info.value.title,
			path: page + '?id=' + pages[pages.length - 1].options.id + '&puserId=' + local.get('userinfo').id,
		}
	})
	onShareTimeline(function(res) {
		return {
			title: info.value.title,
			path: page + '?id=' + pages[pages.length - 1].options.id + '&puserId=' + local.get('userinfo').id,
		}
	})
</script>

<style scoped lang="scss">
	button::after {
		border: none;
	}

	button {
		position: relative;
		display: block;
		margin: 0;
		padding: 0;
		box-sizing: border-box;
		text-align: center;
		background-color: rgba(0, 0, 0, 0);
		width: 100%;
		height: 100%;
	}
</style>